"use strict";

const Controller = require("egg").Controller;

class MemberController extends Controller {
  async add() {
    const { ctx, service } = this;
    const memberService = service.member;
    const { memname, memlevel, discount, lowpoint, highpoint, desc } =
      ctx.request.body;
    // 查看角色是否存在
    const name = await memberService.findByMemName(memname);
    if (name) {
      ctx.throw(409, "会员名称已存在");
    }
    const member = await memberService.addMember(
      memname,
      memlevel,
      discount,
      lowpoint,
      highpoint,
      desc
    );
    ctx.apiSuc("新增成功", member);
  }
  async del() {}
  async edit() {}
  async list() {}
}

module.exports = MemberController;
